package DesignPattern.SingletonPattern;

public class SingletonTest0 {
    public static void main(String[] args) {
//        GirlFriend girlFriend0 = GirlFriend.getInstance();
//        System.out.println(girlFriend0);
//
//        GirlFriend girlFriend1 = GirlFriend.getInstance();
//        System.out.println(girlFriend1);
//        System.out.println(girlFriend0 == girlFriend1);
        System.out.println(GirlFriend.age);
    }
}

class GirlFriend{
    private String name;
    public static int age = 18;
    //单例模式：饿汉式 类一旦加载就会创建完成。通常用于重量级对象
    //步骤1：构造器私有化
    private GirlFriend(String name) {
        System.out.println("构造器被调用了");
        this.name = name;
    }

    //2.在类的内部创建一个静态对象
    private static GirlFriend girlFriend = new GirlFriend("honey");

    //3. 提供一个公共的static方法返回gf对象
    public static GirlFriend getInstance(){
        return girlFriend;
    }
}